//* detect touch devices
function is_touch_device() {
    return !!('ontouchstart' in window);
}
$(document).ready(function() {
    //* accordion change actions
    $('#side_accordion').on('hidden shown', function () {
        gebo_sidebar.make_scroll();
        gebo_sidebar.update_scroll();
    });


    //mouse hover nav
    $('header li.dropdown').mouseenter(function() {
        if($('body').hasClass('menu_hover')) {
            $(this).addClass('navHover')
        }
    }).mouseleave(function() {
        if($('body').hasClass('menu_hover')) {
            $(this).removeClass('navHover open')
        }
    });
    gebo_sidebar.make_scroll();
    gebo_sidebar.update_scroll();
    //active parent
    $(".accordion-inner .nav-list li.active").parent("ul").parent(".accordion-inner").parent(".accordion-body").addClass("in").css("height", "auto");
});

gebo_sidebar = {
    init: function() {
        // sidebar onload state
        if($(window).width() > 979){
            if(!$('body').hasClass('sidebar_hidden')) {
                if( $.cookie('gebo_sidebar') == "hidden") {
                    $('body').addClass('sidebar_hidden');
                    $('.sidebar_switch').toggleClass('on_switch off_switch').attr('title','Show Sidebar');
                }
            } else {
                $('.sidebar_switch').toggleClass('on_switch off_switch').attr('title','Show Sidebar');
            }
        } else {
            $('body').addClass('sidebar_hidden');
            $('.sidebar_switch').removeClass('on_switch').addClass('off_switch');
        }

        gebo_sidebar.info_box();
        //* sidebar visibility switch
        $('.sidebar_switch').click(function(){
            $('.sidebar_switch').removeClass('on_switch off_switch');
            if( $('body').hasClass('sidebar_hidden') ) {
                $.cookie('gebo_sidebar', null);
                $('body').removeClass('sidebar_hidden');
                $('.sidebar_switch').addClass('on_switch').show();
                $('.sidebar_switch').attr( 'title', "Hide Sidebar" );
            } else {
                $.cookie('gebo_sidebar', 'hidden');
                $('body').addClass('sidebar_hidden');
                $('.sidebar_switch').addClass('off_switch');
                $('.sidebar_switch').attr( 'title', "Show Sidebar" );
            }
            gebo_sidebar.info_box();
            gebo_sidebar.update_scroll();
            $(window).resize();
        });
        //* prevent accordion link click
        $('.sidebar .accordion-toggle').click(function(e){
            e.preventDefault()
        });
    },
    info_box: function(){
        var s_box = $('.sidebar_info');
        var s_box_height = s_box.actual('height');
        s_box.css({
            'height'        : s_box_height
        });
        $('.push').height(s_box_height);
        $('.sidebar_inner').css({
            'margin-bottom' : '-'+s_box_height+'px',
            'min-height'    : '100%'
        });
    },
    make_active: function() {
        var thisAccordion = $('#side_accordion');
        thisAccordion.find('.accordion-heading').removeClass('sdb_h_active');
        var thisHeading = thisAccordion.find('.accordion-body.in').prev('.accordion-heading');
        if(thisHeading.length) {
            thisHeading.addClass('sdb_h_active');
        }
    },
    make_scroll: function() {
        antiScroll = $('.antiScroll').antiscroll().data('antiscroll');
    },
    update_scroll: function() {
        if($('.antiScroll').length) {
            if( $(window).width() > 979 ){
                $('.antiscroll-inner, .antiscroll-content').height($(window).height() - 40);
                //$('.antiscroll-content').height($(window).height() - 60);
            } else {
                $('.antiscroll-inner,.antiscroll-content').height('400px');
            }
            antiScroll.refresh();
        }
    }
};
